package com.xinxin.leetcode.problem234;

import com.xinxin.leetcode.common.ListNode;

/**
 * @author ShiXinXin
 * @date 2019-08-29 20:14
 */
class Solution {
    public boolean isPalindrome(ListNode head) {
        ListNode slow = head, fast = head, prev = null;
        while (fast != null) {
            slow = slow.next;
            fast = fast.next != null ? fast.next.next : null;
        }
        while (slow != null) {
            ListNode ovn = slow.next;
            slow.next = prev;
            prev = slow;
            slow = ovn;
        }
        while (head != null && prev != null) {
            if (head.val != prev.val) {
                return false;
            }
            head = head.next;
            prev = prev.next;
        }
        return true;
    }
}
